package org.gd.hellojavacore.enums;

import java.util.HashMap;
import java.util.Map;

public enum DepositState {

    OPENED("r", new String[]{"O", "X", "B", "r", "s", "BA", "BB", "BC", "BM", "R"}),
    LONG("l", new String[]{"L","T","U"}),
    PROCESSING("p", new String[]{"p","x"}),
    CLOSED("c", new String[]{"C"}),
    TERMINATED("t", new String[]{"K","Z"}),
    ERROR("e", new String[]{"b", "e", "t"}),
    //BLOCKED("b", new String[]{"X", "B", "BA", "BB", "BC", "BM", "BS", "CL", "KU", "KV", "KX", "SB", "KA", "KE", "KB", "EX", "KD", "RV", "IP", "ZK", "KC"}),
    ALL(null, new String[]{"%"});

    private String[] factStates;
    private String stateNameForUser;

    private DepositState(String stateNameForUser, String[] factStates) {
        this.factStates = factStates;
        this.stateNameForUser = stateNameForUser;
    }

    public String[] getFactStates(){
        return this.factStates;
    }

    public String getStateNameForUser(){
        return this.stateNameForUser;
    }

    public boolean equalsTo(String stateNameForUser){
        return this.stateNameForUser.equals(stateNameForUser);
    }

    private static Map<String, String> getFStatesToUStatesMap(DepositState depositState){
        Map<String, String> result = new HashMap<String, String>();
        switch (depositState) {
            case ALL:
                return getAllFStatesToUStatesMap();
            default:
                String stateNameForUser = depositState.getStateNameForUser();
                String[] factStates = depositState.getFactStates();
                for (String factState : factStates) {
                    result.put(factState, stateNameForUser);
                }
                break;
        }
        return result;
    }

    private static Map<String, String> getAllFStatesToUStatesMap(){
        HashMap<String, String> result = new HashMap<String, String>();
        DepositState[] depositStates= DepositState.values();
        for (DepositState depositState : depositStates) {
            if (depositState != ALL) {
                Map<String, String> map = getFStatesToUStatesMap(depositState);
                result.putAll(map);
            }
        }
        return result;
    }

}
